﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.Core.AppVersion;
using FwProject.ShoppingMall.Com;
using FwProject.ShoppingMall.EventAdvertising;

namespace FwProject.Manager
{
    public class ShopOrderDetailsManager : IDomainService
    {
        private readonly IRepository<ShopOrderDetails, Guid> _shopOrderDetailsRepository;
        private readonly IRepository<ShopCar, Guid> _shopCarRepository;

        public ShopOrderDetailsManager(IRepository<ShopOrderDetails, Guid> shopOrderDetailsRepository,
            IRepository<ShopCar, Guid> shopCarRepository)
        {
            _shopOrderDetailsRepository = shopOrderDetailsRepository;
            _shopCarRepository = shopCarRepository;
        }
        /// <summary>
        /// 添加一个订单明细
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<Guid> CreateShopOrderDetails(ShopOrderDetails model)
        {
            var m=_shopCarRepository.GetAll().Where(o => o.ShopproductId == model.ShopproductId).FirstOrDefault();
            if (m != null)
               await  _shopCarRepository.DeleteAsync(m);

            return await _shopOrderDetailsRepository.InsertAndGetIdAsync(model);
           
        }
        /// <summary>
        /// 修改一个订单明细
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>

        public async Task UpdateShopOrderDetails(ShopOrderDetails model)
        {
            await _shopOrderDetailsRepository.UpdateAsync(model);
        }

        /// <summary>
        /// 删除一个订单明细
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task DeleteShopOrderDetails(ShopOrderDetails model)
        {
            await _shopOrderDetailsRepository.DeleteAsync(model);
        }
    }
}
